package org.coldlife.sim.display;

import javax.swing.JPanel;


public class DrawPanel extends JPanel implements Runnable
{
	private static final long serialVersionUID = 7228388280008890285L;
	private int sleepTime;
	private Thread paintThread;
	private boolean isRunning = false;
	
	public DrawPanel(int sleepTime) 
	{
		super(true);
		this.sleepTime = sleepTime;
		paintThread = new Thread(this, "DrawPanel.paintThread");
	}
	
	public void start()
	{
		paintThread.start();
		isRunning = true;
	}
	
	public void run() 
	{
		while(isRunning)
		{
			runHook();
			
			try 
			{
				Thread.sleep(sleepTime);
			} 
			catch (InterruptedException e) 
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.repaint();
		}
	}

	protected void runHook() 
	{
		
	}

	public void stop()
	{
		isRunning = false;
	}

	public int getSleepTime() {
		return sleepTime;
	}

	public void setSleepTime(int sleepTime) {
		this.sleepTime = sleepTime;
	}	
}
